home *** CD-ROM | disk | FTP | other *** search
- Path: keats.ugrad.cs.ubc.ca!not-for-mail
- From: c2a192@ugrad.cs.ubc.ca (Kazimir Kylheku)
- Newsgroups: comp.lang.c
- Subject: Re: more problems with qsort
- Date: 26 Feb 1996 13:43:35 -0800
- Organization: Computer Science, University of B.C., Vancouver, B.C., Canada
- Message-ID: <4gt9i7INN76i@keats.ugrad.cs.ubc.ca>
- References: <177399702S86.JW1675A@american.edu>
- NNTP-Posting-Host: keats.ugrad.cs.ubc.ca
-
- In article <177399702S86.JW1675A@american.edu>,
- James D. Watson <JW1675A@american.edu> wrote:
- >Hi folks --
- >
- >after reading the FAQ entries about qsort, I thought I had my problem
- >licked, but it seems not.
- >
- >Architecture: SunOS 4.1.3 with ANSI-C compiler.
- >
- >I'm doing some file manipulation and between steps A and B, I need to sort.
- >For various reasons, I don't want to popen() to the sort utility--I want to
- >use qsort. Here's what I'm doing:
- >
- > get number of lines in the file
- > (char**)malloc with enough room for all lines
- > for each line in the file {
- > (char*)malloc(90) /* 90 is enough room for each line in file */
- > copy each line into the newly malloc()ed space
- > point a (char**) to the newly malloc()ed space
- > }
- >
- >so now I should have "lines" number of pointers to pointers to char,
- >each one pointing to 90 bytes containing a line in the file.
- >
- >So, I call qsort(array[0], lines, 90, compare)
- >where compare is my comparison function -- prepared as discussed
- >in the FAQ. Now all I get are core dumps during the call to qsort().
- >:-)
-
- You need a pointer to the first element of the array, not the first element
- itself. You should be calling it qsort(array, ... );
-
- --
-
-